﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Net.Mail;
using IPSWWA.Models;

namespace IPSWWA.Models
{

    public interface IMessage
    {
		//I figure all messages should send
        void Send();
    }

    //spot to change configuration incase server changes
	//
    public abstract class AMessages : IMessage
    {
        public MailMessage mail = new MailMessage();
        public SmtpClient Smtpserver = new SmtpClient(/*redacted server name*/);

        public void Send()
        {
            Smtpserver.Send(mail);
            Smtpserver.Dispose();
        }
    }


    public class IPSEmails : AMessages
    {

        public IPSEmails(string from, string to, string Title, string Body)
        {
            Smtpserver.UseDefaultCredentials = true;
            mail.From = new MailAddress(from);
            mail.To.Add(to);
            mail.Subject = Title;
            mail.Body = Body;
        }
    }
	
    public class IPSFaxEmail : AMessages
    {
		//Sometimes attchments are sent by filename string.
        public IPSFaxEmail(string from, string faxnumber, string Title, string Body, string Filename)
        {
            Smtpserver.UseDefaultCredentials = true;
            mail.From = new MailAddress(from);
            mail.To.Add(faxnumber + "@faxmaker.com");
            mail.Subject = Title;
            mail.Body = Body;
            Attachment afile = new Attachment(Filename);
            mail.Attachments.Add(afile);
        }
	
		//Some files are generated on the spot and sent 
        public IPSFaxEmail(string from, string faxnumber, string Title, string Body, MemoryStream File)
        {
            Smtpserver.UseDefaultCredentials = true;
            mail.From = new MailAddress(from);
            mail.To.Add(faxnumber + "@faxmaker.com");
            mail.Subject = Title;
            mail.Body = Body;
            Attachment afile = new Attachment(File, "Faxemail.pdf");
            mail.Attachments.Add(afile);
        }
    }
	 
    public class MailItemInvoker
    {
        //can later add more functionality here, just need an invoker to get this
        public MailItemInvoker(IMessage Email)
        {
            Email.Send();
        }
    }
}